package com.ggh.controller;
import com.ggh.entity.Recharge;
import com.ggh.entity.Recharger;
import com.ggh.entity.TypeBean;
import com.ggh.service.RechargeService;
import com.ggh.service.RechargerService;
import com.ggh.service.impl.RechargeServiceImpl;
import com.ggh.service.impl.RechargerServiceImpl;
import com.ggh.vo.Body;
import com.ggh.vo.Meta;
import com.ggh.vo.UserToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * 充值
 * @author jj
 * @date 2019/10/14 16:35
 */
@Controller
@RequestMapping("/recharge")
public class RechargeController {
   @Autowired
   private RechargerService rechargerService;
    @Autowired
    private RechargeService rechargeService;


    @PostMapping("/findCzr")
    @ResponseBody
    public UserToken  findCzr(Integer type){
        Recharger rechargeR = rechargerService.findCzr(type);
        if (rechargeR!=null) {
            if (rechargeR.getType()==1) {
                return UserToken.newInstance(0, "HallChongZhiZFBMessage", rechargeR, TypeBean.SUCCESS);
            }else {
                return UserToken.newInstance(0, "HallChongZhiBankMessage", rechargeR, TypeBean.SUCCESS);
            }
        }
        return null;
        }
    /**
    * @description :充值
    * @param recharge
    * @return: com.ggh.vo.UserToken
    * @date : 2019/10/17 9:59
    * @author : jj
    * @throws
    */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public UserToken add(Recharge recharge){

        Boolean isSuccess = rechargeService.addpay(recharge);
        return recharge.getType()==1 ?
                isSuccess ?
                        UserToken.newInstance(recharge.getUserid(),"HallChongZhiZFBSend","充值成功", TypeBean.SUCCESS)
                        :UserToken.newInstance(recharge.getUserid(),"HallChongZhiZFBSend","充值失败", TypeBean.SUCCESS):
                isSuccess ?
                        UserToken.newInstance(recharge.getUserid(),"HallChongZhiBankSend","充值成功", TypeBean.SUCCESS)
                        :UserToken.newInstance(recharge.getUserid(),"HallChongZhiBankSend","充值失败", TypeBean.SUCCESS);
    }
    /**
    * @description :查询全部记录
    * @return: java.util.List<com.ggh.entity.Recharge>
    * @date : 2019/10/17 11:08
    * @author : jj
    * @throws
    */
    @RequestMapping(value = "/findAll", method = RequestMethod.POST)
    @ResponseBody
    public List<Recharge> findAll(){
        List<Recharge> all = rechargeService.findAll();
        return all;
    }
    /**
    * @description :查询审核数据
    * @return: java.util.List<com.ggh.entity.Recharge>
    * @date : 2019/10/17 11:09
    * @author : jj
    * @throws
    */
    @RequestMapping(value = "/findSh", method = RequestMethod.POST)
    @ResponseBody
    public Body findSh(){
        List<Recharge> all = rechargeService.findSh();
        return Body.newInstance(Meta.CODE_200,all);
    }
    /**
    * @description :更新审核状态
    * @param recharge 
    * @return: com.ggh.vo.Body
    * @date : 2019/10/17 11:16
    * @author : jj
    * @throws
    */
    public Body updateStatus(Recharge recharge){
        boolean update = rechargeService.update(recharge);
        if (update){
            return  Body.newInstance();
        }else {
            return Body.newInstance(400,"错误");
        }
    }
}
